package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.motion.widget.MotionLayout;
import androidx.constraintlayout.utils.widget.ImageFilterView;

public class MainActivity14 extends AppCompatActivity {

    private MotionLayout mMotionLayout;
    private ImageFilterView mImage;

    private boolean state = false;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity14.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main14 );
        initView();
        initViewAction();
    }

    private void initView() {

        mMotionLayout = (MotionLayout) findViewById( R.id.motionLayout );
        mImage = (ImageFilterView) findViewById( R.id.image );
    }

    private void initViewAction() {

        mImage.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                float progress = mMotionLayout.getProgress();
                if ( progress > 0f && progress < 1f ) {
                    return;
                }

                if ( state ) {
                    mMotionLayout.setTransition( R.id.reverse );
                    mMotionLayout.transitionToState( R.id.start );
                } else {
                    mMotionLayout.setTransition( R.id.forward );
                    mMotionLayout.transitionToState( R.id.next );
                }

                state = !state;
            }
        } );
    }
}